package com.team.appinfo.controller.admin;

import com.github.pagehelper.PageInfo;
import com.team.appinfo.entity.*;
import com.team.appinfo.service.AppVersionService;
import com.team.appinfo.service.AppinfoService;
import com.team.appinfo.util.FileUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;

@Controller(value = "AdminAppInfoController")
public class AppInfoController {
    @Autowired
    private AppinfoService appinfoService;
    @Autowired
    private AppVersionService appVersionService;


    @RequestMapping("/getAdminAppInfo")  //条件查询所有用户下的app信息
    public String getAdminAppInfo(AppInfoTiaoJian appInfoTiaoJian, Model model, HttpSession session){
        PageInfo<AppInfoConstant> pageinfo = this.appinfoService.getAdminAppInfo(appInfoTiaoJian);
        BackendUser bu =( BackendUser)session.getAttribute("bu");
        model.addAttribute("bu",bu);
        model.addAttribute("tiaojian",appInfoTiaoJian); //条件
        model.addAttribute("pageInfo",pageinfo ); //数据
            return "backend/applist";

    }
    //查询app信息进行审核  id表示app信息的编号
    @RequestMapping("/goAppInfoCheck")
    public String goAppInfoCheck(Long id,Model model){
        //1.查询app信息进行展示
        AppInfoConstant appInfoConstant = appinfoService.goAppInfoCheck(id);

        //2.查询app对应的最新版本信息展示
        AppVersion appVersion= appVersionService.getLastVersionInfo(id);

        model.addAttribute("appinfo",appInfoConstant);
        model.addAttribute("appVersion",appVersion);
        return "backend/appcheck";
    }

    //修改app审核状态
    @RequestMapping("/ShenHeAppInfo")
    public String ShenHeAppInfo(Long status,Long id){
        int www = appinfoService.xiugaiAppInfoZhuangtai(status, id);
    if (www>0){
        return "redirect:getAdminAppInfo";
    }else {
        return "redirect:getAdminAppInfo";
    }

    }
}
